<?

class player{

	var $id;
	var $nom;
	var $level;
	var $race;
	var $classe;
	var $sexe;
	var $guilde;
	var $idUser;
	var $grade;
	var $talents1;
	var $talents2;
	var $spe1;
	var $spe2;
	var $metier1;
	var $niveau1;
	var $metier2;
	var $niveau2;
	var $stuff;
	var $xml;
	var $ts;
	var $casual;

	function player($var){
		global $sql, $data_classes_role;
		if(is_numeric($var)){
			$var=$sql->request_single("select * from ".CFG_MYSQL_PREFIX."player where id=".$var);
		}
		
		if(is_object($var)){
			$this->id=$var->id;
			$this->nom=$var->nom;
			$this->level=$var->level;
			$this->race=$var->race;
			$this->classe=$var->classe;
			$this->sexe=$var->sexe;
			$this->guilde=$var->guilde;
			$this->idUser=$var->idUser;
			$this->grade=$var->grade;
			$this->talents1=$var->talents1;
			$this->talents2=$var->talents2;
			$this->spe1=$data_classes_role[$var->classe][$var->talents1];
			$this->spe2=$data_classes_role[$var->classe][$var->talents2];
			$this->metier1=$var->metier1;
			$this->niveau1=$var->niveau1;
			$this->metier2=$var->metier2;
			$this->niveau2=$var->niveau2;
			$this->stuff=$var->stuff;
			$this->xml=$var->xml;
			$this->ts=$var->ts;
			$this->casual=$var->casual;
		}elseif(is_array($var)){
			$this->id=$var["id"];
			$this->nom=$var["nom"];
			$this->level=$var["level"];
			$this->race=$var["race"];
			$this->classe=$var["classe"];
			$this->sexe=$var["sexe"];
			$this->guilde=$var["guilde"];
			$this->idUser=$var["idUser"];
			$this->grade=$var["grade"];
			$this->talents1=$var["talents1"];
			$this->talents2=$var["talents2"];
			$this->spe1=$var["spe1"];
			$this->spe2=$var["spe2"];
			$this->metier1=$var["metier1"];
			$this->niveau1=$var["niveau1"];
			$this->metier2=$var["metier2"];
			$this->niveau2=$var["niveau2"];
			$this->stuff=$var["stuff"];
			$this->xml=$var["xml"];
			$this->ts=$var["ts"];
			$this->casual=$var["casual"];
		}
	}

	function get_id(){ return stripslashes($this->id); }
	function set_id($value){ $this->id=$value; }
	function get_nom(){ return stripslashes($this->nom); }
	function set_nom($value){ $this->nom=$value; }
	function get_level(){ return stripslashes($this->level); }
	function set_level($value){ $this->level=$value; }
	function get_race(){ return stripslashes($this->race); }
	function set_race($value){ $this->race=$value; }
	function get_classe(){ return stripslashes($this->classe); }
	function set_classe($value){ $this->classe=$value; }
	function get_sexe(){ return stripslashes($this->sexe); }
	function set_sexe($value){ $this->sexe=$value; }
	function get_guilde(){ return stripslashes($this->guilde); }
	function set_guilde($value){ $this->guilde=$value; }
	function get_idUser(){ return stripslashes($this->idUser); }
	function set_idUser($value){ $this->idUser=$value; }
	function get_grade(){ return stripslashes($this->grade); }
	function set_grade($value){ $this->grade=$value; }
	function get_talents1(){ return stripslashes($this->talents1); }
	function set_talents1($value){ $this->talents1=$value; }
	function get_talents2(){ return stripslashes($this->talents2); }
	function set_talents2($value){ $this->talents2=$value; }
	function get_spe1(){ return stripslashes($this->spe1); }
	function set_spe1($value){ $this->spe1=$value; }
	function get_spe2(){ return stripslashes($this->spe2); }
	function set_spe2($value){ $this->spe2=$value; }
	function get_metier1(){ return stripslashes($this->metier1); }
	function set_metier1($value){ $this->metier1=$value; }
	function get_niveau1(){ return stripslashes($this->niveau1); }
	function set_niveau1($value){ $this->niveau1=$value; }
	function get_metier2(){ return stripslashes($this->metier2); }
	function set_metier2($value){ $this->metier2=$value; }
	function get_niveau2(){ return stripslashes($this->niveau2); }
	function set_niveau2($value){ $this->niveau2=$value; }
	function get_stuff(){ return stripslashes($this->stuff); }
	function set_stuff($value){ $this->stuff=$value; }
	function get_xml(){ return stripslashes($this->xml); }
	function set_xml($value){ $this->xml=$value; }
	function get_ts(){ return stripslashes($this->ts); }
	function set_ts($value){ $this->ts=$value; }
	function get_casual(){ return stripslashes($this->casual); }
	function set_casual($value){ $this->casual=$value; }


	function ajouter(){
		global $sql;
		$sqlr="insert into ".CFG_MYSQL_PREFIX."player(nom,level,race,classe,sexe,guilde,idUser,grade,talents1,talents2,spe1,spe2,metier1,niveau1,metier2,niveau2,stuff,xml,ts,casual) values('".addslashes($this->nom)."','".addslashes($this->level)."','".addslashes($this->race)."','".addslashes($this->classe)."','".addslashes($this->sexe)."','".addslashes($this->guilde)."','".addslashes($this->idUser)."','".addslashes($this->grade)."','".addslashes($this->talents1)."','".addslashes($this->talents2)."','".addslashes($this->spe1)."','".addslashes($this->spe2)."','".addslashes($this->metier1)."','".addslashes($this->niveau1)."','".addslashes($this->metier2)."','".addslashes($this->niveau2)."','".addslashes($this->stuff)."','".addslashes($this->xml)."','".addslashes($this->ts)."','".addslashes($this->casual)."')";
		$sql->query($sqlr,0);
	}

	function maj(){
		global $sql;
		$query = "update ".CFG_MYSQL_PREFIX."player set nom='".addslashes($this->nom)."',level='".addslashes($this->level)."',race='".addslashes($this->race)."',classe='".addslashes($this->classe)."',sexe='".addslashes($this->sexe)."',guilde='".addslashes($this->guilde)."',idUser='".addslashes($this->idUser)."',grade='".addslashes($this->grade)."',talents1='".addslashes($this->talents1)."',talents2='".addslashes($this->talents2)."',spe1='".addslashes($this->spe1)."',spe2='".addslashes($this->spe2)."',metier1='".addslashes($this->metier1)."',niveau1='".addslashes($this->niveau1)."',metier2='".addslashes($this->metier2)."',niveau2='".addslashes($this->niveau2)."',stuff='".addslashes($this->stuff)."',xml='".addslashes($this->xml)."',ts='".($this->ts)."',casual='".(int)$this->casual."' where id=".$this->id;
		$sql->query($query,0);
	}

	function exists(){
		global $sql;
		$var=$sql->request_single("select id,idUser from ".CFG_MYSQL_PREFIX."player where nom='".$this->nom."'",0);
		if($var!==false){
			$this->id=$var->id;
			$this->idUser=$var->idUser;
			return true;
		}else return false;
	}

	function get_portrait(){
		$json = unserialize($this->xml);
		return "http://eu.battle.net/static-render/eu/".$json->thumbnail;
	}

	function get_datas(){
		global $data_races, $data_classes, $data_classes_infos, $data_classes_role, $cfg_params;
	
		$datas=array();
		
		$datas["ID"]=$this->id;
		
		$datas["NOM"]=$this->nom;
		$datas["LEVEL"]=$this->level;
		$datas["RACE"]=$this->race;
		$datas["SEXE"]=$this->sexe;
		$datas["RACE_STR"]=$data_races[$this->race."-".$this->sexe];
		$datas["CLASSE"]=$this->classe;
		$datas["CLASSE_STR"]=$data_classes[$this->classe][$this->sexe];
		$datas["GUILDE"]=$this->guilde;
		$datas["GRADE"]=$this->grade;

		if(isset($cfg_params["liste_rangs"])) $datas["GRADE_STR"]=$cfg_params["liste_rangs"][$this->grade];
		
		$datas["TALENTS1"]=$this->talents1;
		$datas["TALENTS2"]=$this->talents2;
		$datas["SPE1"]=$data_classes_role[$this->classe][$this->talents1];
		$datas["SPE2"]=$data_classes_role[$this->classe][$this->talents2];
		
		$datas["SPE1_STR"]=$data_classes_infos[$this->classe][1][$this->spe1];
		$datas["SPE2_STR"]=$data_classes_infos[$this->classe][1][$this->spe2];
		$datas["METIER1"]=$this->metier1;
		$datas["METIER1_NIVEAU"]=$this->niveau1;
		$datas["METIER1_ICO"]=get_ico_metier($this->metier1);
		$datas["METIER2"]=$this->metier2;
		$datas["METIER2_NIVEAU"]=$this->niveau2;
		$datas["METIER2_ICO"]=get_ico_metier($this->metier2);
		$datas["DATE_MAJ"]=date("d/m/Y",$this->ts);
		
		$datas["PORTRAIT"]=$this->get_portrait();
		
		$datas["URL_ARMORY"]="http://".CFG_SERVEUR.".battle.net/wow/fr/character/".CFG_ROYAUME."/".$this->nom."/simple";
		
		return $datas;
	}
	
	function get_3dmodel(){
		require_once("./modules/wowhead_items/library/lib.wowheaditem.php");
		require_once("./modules/wowhead_items/classes/class.wowheaditem.php");
		$str="";
		$tmp=array();
		if($this->race==1) $str.="human";
		if($this->race==3) $str.="dwarf";
		if($this->race==7) $str.="gnome";
		if($this->race==4) $str.="nightelf";
		if($this->race==11) $str.="draenei";
		if($this->race==25) $str.="pandaren";
		
		if($this->sexe==0) $str.="male";
		if($this->sexe==1) $str.="female";
		
		$tmp["racesexe"]=$str;
		
		$str="";
		$equips=explode(",",$this->stuff);
		foreach($equips as $equip){
			$item=wowhead_getItem($equip);
			$d=array(2,4,11,12,15,24,25,26);
			if(!in_array($item->slot,$d)) $str.=$item->slot.",".$item->model.",";
		}
		$tmp["equipList"]=substr($str,0,-1);
		
		return $tmp;
	}
	
	function get_items(){
	/*********************************************************/
	/*********************************************************/
	/**														**/
	/**														**/
	/**	TODO: virer le return $str et voir ce que ça fait ! --/
	/**														**/
	/**														**/
	/**														**/
	/*********************************************************/
	/*********************************************************/
	
		return $str;
		global $sql;

		$str="";
		
		$equips=explode(",",$this->stuff);
		foreach($equips as $equip){
			$item=wowhead_getItem($equip);
			if($item->slot==24) $str.="<div class='wowheaditem_tooltip roster_player_item".$item->slot."' id='item".$item->idItem."' style='background-image: url(http://static.wowhead.com/images/icons/small/".strtolower($item->icon).".jpg); background-position: 4px 4px; background-repeat: no-repeat; '><div style='background-image: url(http://static.wowhead.com/images/icon_border_small.png); width: 26px; height: 26px;'></div></div>";
			elseif(($item->slot==11)||($item->slot==12)){
				if(strpos($str,"roster_player_item".$item->slot)!==false) $str.="<div class='wowheaditem_tooltip roster_player_item".$item->slot." roster_player_item".$item->slot."_bis' id='item".$item->idItem."' style='background-image: url(http://static.wowhead.com/images/icons/medium/".strtolower($item->icon).".jpg); background-position: 4px 4px; background-repeat: no-repeat; '><div style='background-image: url(http://static.wowhead.com/images/icon_border_medium.png); width: 44px; height: 44px;'></div></div>";
				else $str.="<div class='wowheaditem_tooltip roster_player_item".$item->slot."' id='item".$item->idItem."' style='background-image: url(http://static.wowhead.com/images/icons/medium/".strtolower($item->icon).".jpg); background-position: 4px 4px; background-repeat: no-repeat; '><div style='background-image: url(http://static.wowhead.com/images/icon_border_medium.png); width: 44px; height: 44px;'></div></div>"; 
			}else $str.="<div class='wowheaditem_tooltip roster_player_item".$item->slot."' id='item".$item->idItem."' style='background-image: url(http://static.wowhead.com/images/icons/medium/".strtolower($item->icon).".jpg); background-position: 4px 4px; background-repeat: no-repeat; '><div style='background-image: url(http://static.wowhead.com/images/icon_border_medium.png); width: 44px; height: 44px;'></div></div>";
		}
		
		return $str;
	}

	function get_classColor(){
		global $data_classes_infos;
		return $data_classes_infos[$this->classe][0];
	}
	
	function get_classType(){
		global $data_classes_infos;
		return $data_classes_infos[$this->classe][2][$this->spe1];
	}
}